from django.test import TestCase
import datetime
from xBlog.TimezoneUtils import local2utc, utc2local
import pytz
from django.utils import timezone


class TimezoneUtils_tests(TestCase):
    def test_local2utc(self):
        local_datetime = datetime.datetime.now()
        utc_datetime = pytz.utc.localize(datetime.datetime.utcnow())
        result = local2utc(local_datetime)
        diff = utc_datetime - result
        self.assertTrue(diff.seconds < 1)

    def test_utc2local(self):
        utc_datetime = datetime.datetime.utcnow()
        local_datetime = timezone.get_current_timezone().localize(datetime.datetime.now())
        result = utc2local(utc_datetime)
        diff = local_datetime - result
        print(result, local_datetime)
        self.assertTrue(diff.seconds < 1)
